function All() {}
All.prototype = {
  timer: "",
  debounce(fn, delay = 500) {
    var _this = this;
    return function (arg) {
      //获取函数的作用域和变量
      let that = this;
      let args = arg;
      clearTimeout(_this.timer); // 清除定时器
      _this.timer = setTimeout(function () {
        fn.call(that, args);
      }, delay);
    };
  },
  setCookie(val) {
    //cookie设置[{key:value}]、获取key、清除['key1','key2']
    for (var i = 0, len = val.length; i < len; i++) {
      for (var key in val[i]) {
        document.cookie =
          key + "=" + encodeURIComponent(val[i][key]) + "; path=/";
      }
    }
  },
  getCookie(name) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0, len = arrCookie.length; i < len; i++) {
      var arr = arrCookie[i].split("=");
      if (name == arr[0]) {
        return decodeURIComponent(arr[1]);
      }
    }
  },
  clearCookie(name) {
    var myDate = new Date();
    myDate.setTime(-1000); //设置时间
    for (var i = 0, len = name.length; i < len; i++) {
      document.cookie =
        "" + name[i] + "=''; path=/; expires=" + myDate.toGMTString();
    }
  },
  arrToStr(arr) {
    if (arr) {
      return arr
        .map((item) => {
          return item.name;
        })
        .join("、");
    }
  },
  toggleClass(arr, elem, key = "id") {
    return arr.some((item) => {
      return item[key] == elem[key];
    });
  },
  toChecked(arr, elem, key = "id") {
    var isIncludes = this.toggleClass(arr, elem, key);
    !isIncludes ? arr.push(elem) : this.removeEle(arr, elem, key);
  },
  removeEle(arr, elem, key = "id") {
    var includesIndex;
    arr.map((item, index) => {
      if (item[key] == elem[key]) {
        includesIndex = index;
      }
    });
    arr.splice(includesIndex, 1);
  },
  //设置经办人
  setApproverStr(nodeConfig) {
    if (nodeConfig.nodeUserList.length > 0) {
      return this.arrToStr(nodeConfig.nodeUserList);
    }
  },
  dealStr(type, list) {
    let obj = list.find((item) => item.value == type);
    return obj.label;
  },
  mapLabelStr(value, list) {
    let arr = list.filter((item) => value.includes(item.value));
    let labelArr = arr.map((item) => item.label);
    return labelArr.join("、");
  },
  mapStr(list) {
    let arr = list.map((item) => item.name);
    return arr.join("、");
  },
  conditionStr(nodeConfig, index) {
    var { conditionList, editable } = nodeConfig.conditionNodes[index];
    if (conditionList.length == 0) {
      return editable == false ? "其他条件进入此流程" : "请设置条件";
    } else {
      let str = "";
      for (var i = 0; i < conditionList.length; i++) {
        for (var j = 0; j < conditionList[i].length; j++) {
          var {
            formName,
            conditionType,
            conditionTypeList,
            showType,
            value,
            optionList,
          } = conditionList[i][j];
          //选择框
          if (showType == 1) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              this.dealStr(value, optionList) +
              " 并且 ";
          }
          //单选框
          if (showType == 2.1) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              this.dealStr(value, optionList) +
              " 并且 ";
          }
          //多选框
          if (showType == 2.2) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              this.mapLabelStr(value, optionList) +
              " 并且 ";
          }
          //数组框
          if (showType == 2) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              this.mapStr(value) +
              " 并且 ";
          }
          //文本框
          if (showType == 3) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              value +
              " 并且 ";
          }
          if (
            showType == 4 ||
            showType == 4.1 ||
            showType == 4.2 ||
            showType == 4.3
          ) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              value +
              " 并且 ";
          }
          if (showType == 5) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              " 并且 ";
          }
          if (showType == 6) {
            str +=
              formName +
              this.dealStr(conditionType, conditionTypeList) +
              "：" +
              value +
              " 并且 ";
          }
        }
        str = str.substring(0, str.length - 4);
        str += " 或满足 ";
      }
      return str ? str.substring(0, str.length - 5) : "请设置条件";
    }
  },
  copyerStr(nodeConfig) {
    if (nodeConfig.nodeUserList.length != 0) {
      return this.arrToStr(nodeConfig.nodeUserList);
    }
  },
  toggleStrClass(item, key) {
    let a = item.zdy1 ? item.zdy1.split(",") : [];
    return a.some((item) => {
      return item == key;
    });
  },
};

export default new All();
